package com.first.community.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class LogoutController {


    @GetMapping("/logout")
    public String logout(HttpServletRequest request,
                         HttpServletResponse response){

        //删除session
        request.getSession().removeAttribute("user");


        //删除Cookie
        Cookie cookie = new Cookie("token", null);
        cookie.setMaxAge(0);
        response.addCookie(cookie);


        return "redirect:/";
    }

}
